import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2025-01-17
 * Time: 11:06
 */
public class IsHappy {
    public Integer sum(int n) {
        int sum = 0;
        while (n != 0) {
            sum += Math.pow(n%10, 2);
            n /= 10;
        }
        return sum;
    }
    public boolean isHappy(int n) {
        int fast = sum(sum(n));
        int low = sum(n);
        while (low != 1 && fast != 1 && low != fast) {
            low = sum(n);
            fast = sum(sum(n));
        }
        if (low == fast) {
            return false;
        }
        return true;
    }
}
